<!--新增和编辑 发货单-->
<template>
    <div class="pm50">
        <div class="fz14 bbm pm10">
            <span class="titles">基础信息</span>
        </div>
        <zhqcForm :csk="csk" :rules="rules" :fieldList="fieldList" @submitForm="submitForm" ref="zhqcForm"></zhqcForm>
        <div v-if="ListDetails">
            <div class="fz14 bbm pm10 mt30">
                <span class="titles">列表详情</span>
            </div>
            <div class="mt20">
                <el-button icon="el-icon-plus" @click="addxinzhhs">新增</el-button>
            </div>
            <el-table :data="tahggb" class="mt20 fz12" border>
                <el-table-column type="index" width="50" label="序号" align="center"></el-table-column>
                <el-table-column :prop="sd.prop" :label="sd.label" align="center" v-for="sd in ListDetails">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row[sd.prop]" size="small" v-if="sd.type == 0"></el-input>
                        <el-input-number size="small" v-model="scope.row[sd.prop]" :min="1" v-if="sd.type == 5"></el-input-number>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="90">
                    <template slot-scope="scope">
                        <div class="kkmmxdert">
                            <el-button type="danger" @click="deltable(scope.$index)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pt10 pm10 btm cen fdrtrter">
            <div class="inmkxetr">
                <el-button @click="backs">关闭</el-button>
                <el-button type="primary" @click="baocun">
                    {{type==1?'新增':'保存'}}
                </el-button>
            </div>
        </div>
    </div>
</template>
<script>
    import {
        fieldList,
        ListDetails,
        urlLIst
    } from './js/DetailsModel'
    import zhqcForm from '@/components/zhqcForm'
    import {
        RefactoringObject
    } from '@/util'
    export default {
        data() {
            return {
                type: 0, // 1新增 2编辑 3查看
                jknmxe: '',
                csk: {}, // 传值的参数
                tahggb: [],
                rules: {}, // 验证规则
                jsonobj: {}
            }
        },
        components: {
            zhqcForm
        },
        computed: {
            fieldList() {
                fieldList.map(a => {
                    let kjjknjs = 'blur',
                        kknsse = '请输入'
                    if (a.required) {
                        if (a.type != 0) {
                            kjjknjs = 'change'
                            kknsse = '请选择'
                        }
                        this.rules[a.prop] = [{
                            required: true,
                            message: kknsse + a.label,
                            trigger: kjjknjs
                        }]
                    }
                })
                return fieldList
            },
            ListDetails() {
                return ListDetails
            },
            urlLIst() {
                return urlLIst
            }
        },
        methods: {
            deltable(index) {
                this.$confirm('确认删除选中记录吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.tahggb.splice(index, 1)
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                })
            },
            addxinzhhs() {
                this.tahggb.push(new RefactoringObject(this.ListDetails))
            },
            baocun() {
                this.$refs.zhqcForm.submitForm()
            },
            // 新增按钮触发
            async submitForm() {
                this.csk.subRecords = this.tahggb
                let res = await this.zhycpost(urlLIst.addUrl, this.csk)
            }
        },
        mounted() {},
        activated() {
            this.type = this.$route.meta.type
        }
    }

</script>
<style scoped>


</style>
